package com.example.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.pojo.LF_Inventory;
import com.example.pojo.Materialzhu;
import com.example.pojo.Page;
import com.example.service.LF_InventoryService;

@Controller
@RequestMapping("/lf")
public class LF_InventoryController {
	@Autowired
	private LF_InventoryService invService;
	
	@RequestMapping("/inventory")
	public String index(){ 
		return "lf_pandian" ;
	}
	
	@RequestMapping("/findAll")
	@ResponseBody
	 public Page findAll(int currentPage) {
			// TODO Auto-generated method stub	 
		System.out.println(currentPage);
		   Page page=this.invService.findAll(currentPage);
		   return page;
	}
	
	@RequestMapping(value="/insertInventory",method=RequestMethod.POST)
    @ResponseBody
    public void insertInventory(@RequestBody LF_Inventory inv) {
		System.out.println(inv+"1231321321321");
	// TODO Auto-generated method stub
      this.invService.insertPandian(inv);
   }
	
	@RequestMapping(value="/deletePandian",method=RequestMethod.POST)
	@ResponseBody
	public void deletePandian(@RequestParam String Billno){
		System.out.println("单号传过来是："+Billno);
		this.invService.deletePandian(Billno);
	}
	
	@RequestMapping("/findWu")
	@ResponseBody
	 public List<Materialzhu> findWu(int wareId) {
			// TODO Auto-generated method stub	
		System.out.println(wareId+"=============222222");
		 return this.invService.findWu(wareId);
	}
	
	@RequestMapping("/findDate")
	@ResponseBody
	 public Object findDate(String AdjustDate) {
			// TODO Auto-generated method stub	      
		  Map<String,Object> map=new HashMap<String,Object>();
		  Date date=null;
		  if(AdjustDate==null||AdjustDate.equals("")){
			  date=new java.util.Date();
			  AdjustDate=new SimpleDateFormat("yyyy-MM-dd").format(date);
		  }
		  map.put("AdjustDate", AdjustDate);
		  String billno=this.invService.findDate(AdjustDate);
		  map.put("billno", billno);
		  return map;
	}
	
	
}
